cmake_minimum_required(VERSION 3.10)
project(MaterialIdentify)

# 设置C++标准
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找OpenCV
find_package(OpenCV REQUIRED)

# 查找RKNN相关库
find_library(RKNN_API_LIB librknn_api.so)
find_library(RGA_LIB librga.so)

# 包含目录
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(include)
include_directories(include/det)
include_directories(include/rga)
include_directories(rknn_api)

# 源文件
set(SOURCES
    src/postprocess.cpp
    src/preprocess.cc
    src/rkpt.cc
)

# 创建库
add_library(material_detect STATIC ${SOURCES})
target_link_libraries(material_detect ${OpenCV_LIBS} ${RKNN_API_LIB} ${RGA_LIB})

# 摄像头检测程序
add_executable(camera_detect src/camera_detect.cpp)
target_link_libraries(camera_detect material_detect ${OpenCV_LIBS} ${RKNN_API_LIB} ${RGA_LIB} pthread)


# 模型信息检查程序
add_executable(check_model_info src/check_model_info.cpp)
target_link_libraries(check_model_info ${RKNN_API_LIB})

# 图像缩放测试程序
add_executable(test_image_resize src/test_image_resize.cpp)
target_link_libraries(test_image_resize ${OpenCV_LIBS})

# 模型输出测试程序
add_executable(test_model_output src/test_model_output.cpp)
target_link_libraries(test_model_output ${RKNN_API_LIB})

# 检测功能测试程序
add_executable(test_detection src/test_detection.cpp)
target_link_libraries(test_detection material_detect ${OpenCV_LIBS})

# FP16转换测试程序
add_executable(test_fp16 src/test_fp16.cpp)

# 编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -Wextra")

# 安装规则
install(TARGETS camera_detect
        RUNTIME DESTINATION bin)

# 打印信息
message(STATUS "OpenCV version: ${OpenCV_VERSION}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
message(STATUS "RKNN API library: ${RKNN_API_LIB}")
message(STATUS "RGA library: ${RGA_LIB}")
